<%@ page pageEncoding="UTF-8"%>
<%@ include file="/common/token.jsp"%>
<%@ include file="group.jsp"%>
<%
    String id = input.getDesc("group_id", "-1");
    String groupName = input.getDesc("group_name", "");
    String content = input.getDesc("content", "");
    List<DoctorGroup> list = QBuilder.db("basedb").select().from("DoctorGroup").where(new Where("id=", id).and("status=", STATUS_ENABLE).and("hospital=", hospital)).query().getResultObj();
    if (isEmpty(list)) {
        msg = new Message(30041, "该分组不存在");
        Tools.encryptPrint(out, msg);
        return;
    }
    DoctorGroup dg = list.get(0);
    if (!isEmpty(groupName)) {
        dg.setGroupName(groupName);
    }
    if (!isEmpty(content)) {
        dg.setContent(content);
    }
    if (dg.getGroupName() == null || dg.getGroupName().length() == 0 || dg.getGroupName().length() > 8) {
        msg = new Message(30061, "分组名称1-8个字符");
        Tools.encryptPrint(out, msg);
        return;
    }
    if (dg.getContent() != null && dg.getContent().length() > 8) {
        msg = new Message(30061, "分组备注0-8个字符");
        Tools.encryptPrint(out, msg);
        return;
    }
  	List<DoctorGroup> groups = QBuilder.db("basedb").select().from("DoctorGroup").where(new Where("doctorUid=", token.getUid()).and("status = ", STATUS_ENABLE).and("hospital =", dg.getHospital()).and("groupName=", dg.getGroupName()).and("id!=", id)).query().getResultObj();
  	if (groups.size() != 0) {
        msg = new Message(30061, "分组已存在");
        Tools.encryptPrint(out, msg);
        return;
  	}
    DBTools.db("basedb").modItem(dg, dg.getId());
    DoctorGroup doctorGroup = DoctorGroup.fromMap(parameters, DoctorGroup.class);
    doctorGroup.setDoctorUid(token.getUid());
    Tools.encryptPrint(out, queryGroup(doctorGroup));
%>
